package com.dgz.system.controller.exam;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.dgz.common.core.controller.BaseController;
import com.dgz.common.core.domain.R;
import com.dgz.common.core.domain.TableDataInfo;
import com.dgz.system.domain.exam.dto.ExamAddDto;
import com.dgz.system.domain.exam.dto.ExamEditDto;
import com.dgz.system.domain.exam.dto.ExamQueryDto;
import com.dgz.system.domain.exam.dto.ExamQuestionAddDto;
import com.dgz.system.domain.exam.vo.ExamDetailVO;
import com.dgz.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: DongGuoZhen
 * @Date: 2025/04/06/16:05
 * @Description:
 */
@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    /**
     * 获取竞赛列表
     * @param examQueryDto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDto examQueryDto) {

        return getTableDataInfo(examService.list(examQueryDto));
    }

    /**
     * 添加竞赛
     * @param examAddDto
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody ExamAddDto examAddDto) {
        return R.ok(examService.add(examAddDto));
    }


    /**
     * 添加竞赛题目
     * @param examQuestionAddDto
     * @return
     */
    @PostMapping("/question/add")
    public R<Void> questionAdd(@RequestBody ExamQuestionAddDto examQuestionAddDto) {
        return toR(examService.questionAdd(examQuestionAddDto));
    }


    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId,Long questionId) {
        return toR(examService.questionDelete(examId,questionId));
    }

    /**
     * 获取竞赛详情
     * @param examId
     * @return
     */
    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId) {
        return R.ok(examService.detail(examId));
    }


    /**
     * 修改竞赛
     * @param examAddDto
     * @return
     */
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDto examAddDto) {
        return toR(examService.edit(examAddDto));
    }


    /**
     * 删除竞赛
     * @param examId
     * @return
     */
    @DeleteMapping("/delete")
    public R<Void> delete(Long examId) {
        return toR(examService.delete(examId));
    }


    /**
     * 发布竞赛
     * @param examId
     * @return
     */
    @PutMapping("/publish")
    public R<Void> publish(Long examId) {
        return toR(examService.publish(examId));
    }

    /**
     * 取消发布竞赛
     * @param examId
     * @return
     */
    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId) {
        return toR(examService.cancelPublish(examId));
    }
}
